<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <script src="js/swiper-4.2.6.min.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="css/swiper-4.2.6.min.css"/>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="js/public.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/font.js"></script>
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/ui.css">
    <title></title>
    <!-- 开票信息 -->
    <style>
        .main{
            display: none;
        }
        .main.selected{
            display: block;
        }
    </style>
</head>
<body>
<div class="scroll-content2 invoice-info" style="overflow:auto;background: #F5F5F5;">
    <div class="top-public">
        <span class="public-center">开票信息</span>        
        <img src="images/left_icon.png" alt="" class="public-left">
    </div> 
    <div class="form-top">
        <ul>
            <li style="margin-bottom:0.1rem;">
                <span class="left-name">开票金额</span>
                <span class="right-content" style="color:#f00;" id="invoiceMoney">￥0.00</span>
            </li>
            <li>
                <span class="left-name">发票抬头</span>
                <span class="right-content" id="header_name">
                    <!--个人-->
                </span>
            </li>
            <li>
                <span class="left-name">发票抬头类型</span>
                <span class="right-content" id="invoice_type">
                    <!--增值税普通发票-->
                </span>
            </li>
            <li>
                <span class="left-name">服务内容</span>
                <span class="right-content" id="invoice_service">
                </span>
            </li>
            <li>
                <span class="left-name">发票类型</span>
                <div id="invoiceTy" class="right-content tab-btn">
                    <!--<div>电子</div>-->
                    <div class="active">纸质</div>
                </div>
            </li>
        </ul>
    </div>
    <div class="main-box">
        <div class="main dz">
            <div class="prompt">
                <!--<span>预计5分钟开具</span>-->
                <!--电子发票与纸质发票具有同等法律效益-->
                如需增值税专用发票，请联系客服电话
            </div>
            <ul>
                <li><input readonly class="tax_number" type="text" placeholder="税务登记证号"></li>
                <li><input readonly class="bank" type="text" placeholder="开户银行"></li>
                <li><input readonly class="bank_card" type="text" placeholder="基本开户账号"></li>
                <li><input readonly class="address" type="text" placeholder="注册场所地址"></li>
                <li><input readonly class="fixed_telephone" type="text" placeholder="注册固定电话"></li>
            </ul>
            <div class="sub-btn" onclick="submitSh()">提交申请</div>
        </div>
        <div class="main selected paper">
            <div class="prompt">
                <!--<span>预计5天内送达</span>-->
                <!--电子发票与纸质发票具有同等法律效益-->
                如需增值税专用发票，请联系客服电话
            </div>
            <ul>
                <li><input readonly class="tax_number" type="text" placeholder="税务登记证号"></li>
                <li><input readonly class="bank" type="text" placeholder="开户银行"></li>
                <li><input readonly class="bank_card" type="text" placeholder="基本开户账号"></li>
                <li><input readonly class="address" type="text" placeholder="注册场所地址"></li>
                <li><input readonly class="fixed_telephone" type="text" placeholder="注册固定电话"></li>
            </ul>
            <div class="add-box" onclick="getAddressk()">
                <span class="left-name">收件地址</span>
                <div id="addressH" class="center-box">
                    <!--<div>收件人：<span style="margin-right:0.1rem;">哈哈哈</span><span>13524850733</span></div>-->
                    <!--<div>广东省广州市荔湾区寿山石文化</div>-->
                </div>
            </div>
            <div class="yf">开票金额少于￥200，需邮费到付</div>
            <div class="sub-btn" onclick="submitSh()">提交申请</div>
        </div>
    </div>
</div>
</body>
<script>
    $(function(){
        //验证是否登陆
        var user_id = sessionStorage.getItem('userId');
        if (user_id == null) {
            alert('请先登录！');
            window.location.href = 'login.html';
        }
        //展示订单总额
        var invoiceMoney = sessionStorage.getItem('invoiceMoney');
        $('#invoiceMoney').html('￥'+invoiceMoney);
        //获取个人发票抬头
        getinvoiceTaitou();
        //获取选择的地址
        getaddS();
    });
    function getinvoiceTaitou()
    {
        var user_id = sessionStorage.getItem('userId');
        $.ajax({
            url: url() + 'api/invoice/invoiceHeader', //请求的url地址
            dataType: "JSON", //返回格式为json
            async: true, //请求是否异步，默认为异步，这也是ajax重要特性
            type: "POST", //请求方式
            data:{
                user_id:user_id,
            },
            success: function (data) {
                // console.log(data);
                //请求成功时处理
                if(data.status == 1){
                    $('#header_name').html(data.result.header_name);
                    $('#invoice_type').html(data.result.invoice_type);
                    $('#invoice_service').html(data.result.service);
                    $('.tax_number').val(data.result.tax_number);
                    $('.bank').val(data.result.bank);
                    $('.bank_card').val(data.result.bank_card);
                    $('.address').val(data.result.address);
                    $('.fixed_telephone').val(data.result.fixed_telephone);
                }else {
                    alert('你还没有发票抬头，请先去编辑！');
                    window.location.href = 'invoiceAdmin.html';
                }
            }
        });
    }
    //点击获取地址
    function getAddressk(){
        sessionStorage.setItem('addressType','type');
        window.location.href = 'invoiceAddress.html';
    }
    function getaddS()
    {
        var addressId = sessionStorage.getItem('addressId');
        $.ajax({
            url: url() + 'api/goods/addressOne', //请求的url地址
            dataType: "JSON", //返回格式为json
            async: true, //请求是否异步，默认为异步，这也是ajax重要特性
            type: "POST", //请求方式
            data:{
                address_id:addressId,
            },
            success: function (data) {
                // console.log(data);
                //请求成功时处理
                if(data.status == 1){
                    if (data.result.consignee == null) {
                        var html2 = `
                            <div>请选择地址...<span style="margin-right:0.1rem;"></span><span></span></div>
                            <div></div>
                   `;
                    } else {
                        var html2 = `
                            <div>收件人：<span style="margin-right:0.1rem;">${data.result.consignee}</span><span>${data.result.mobile}</span></div>
                            <div>${data.result.region2}</div>
                   `;
                    }
                }else {
                    var html2 = `
                            <div>收件人：<span style="margin-right:0.1rem;"></span><span></span></div>
                            <div></div>
                   `;
                    alert('网络延迟，请重新选择！');
                }
                $('#addressH').html(html2);
            }
        });
    }
    
    //提交申请
    function submitSh()
    {
        var user_id = sessionStorage.getItem('userId');
        var order_id = sessionStorage.getItem('order_id'); //订单ID
        var invoiceMoney = sessionStorage.getItem('invoiceMoney'); //价格
        console.log(invoiceMoney);
        // var invoiceTy = $('#invoiceTy .active').html(); //发票类型（纸质，电子）目前只有纸质发票
        var addressId = sessionStorage.getItem('addressId'); //地址ID
        if (sessionStorage.getItem('addressId') == null) {
            alert('地址不能为空！');
            return false;
        }
        var invoice_title = $('#header_name').html(); //发票抬头
        var invoice_desc = $('#invoice_service').html(); //服务内容
        var taxpayer = $('.tax_number').val(); //纳税人识别号
        if (invoice_title == '') {
            alert('发票抬头不能为空！');
            return false;
        } if (invoice_desc == '') {
            alert('服务内容不能为空！');
            return false;
        } if (taxpayer == '') {
            alert('纳税人识别号不能为空！');
            return false;
        }
        $.ajax({
            url: url() + 'api/invoice/immediatelyInvoice', //请求的url地址
            dataType: "JSON", //返回格式为json
            async: true, //请求是否异步，默认为异步，这也是ajax重要特性
            type: "POST", //请求方式
            data:{
                user_id:user_id,
                order_id:order_id,
                address_id:addressId,
                invoice_money:invoiceMoney,
                invoice_title:invoice_title,
                invoice_desc:invoice_desc,
                taxpayer:taxpayer,
            },
            success: function (data) {
                //请求成功时处理
                if(data.status == 1){
                    alert(data.msg);
                    window.location.href = 'invoice_info_next.html';
                } else {
                    alert(data.msg);
                    window.location.href = 'invoice_info.html';
                }
            }
        });
    }
</script>
<script>
$('.public-left').click(function(){
    // window.history.go(-1);
    window.location.href = 'invoiceAdmin.html';
})
$('.tab-btn div').click(function () {
    $('.tab-btn div').removeClass('active');
    $(this).addClass('active').siblings().removeClass('active');
    $(".main").eq($(this).index()).show().siblings().hide();
})
</script>

</html> 






